/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs.helsinki.fi.rio.space;

/**
 *
 * @author deiga
 */
public class Space {

    private final int SIZE;

    public Space(int size) {
        this.SIZE = size;
    }

    public Note readNote(Note toRead) {

        return new Note(toRead.id, toRead.get(0));
    }

    public Note removeNote(Note toDelete) {

        return new Note(toDelete.id, toDelete.get(0));
    }
    
    public Note removeNote(String noteID) {
        
        // TODO: Find note with noteID
        
        return new Note(noteID, 0);
    }

    public void postNote(Note toPost) {
    }

    private class Worker extends Thread {

        public void run() {
            while (true) {
                Note t = removeNote("task");
                int row = t.get(0);
                int col = t.get(1);
                Note r = readNote(match("a", row));
                Note c = readNote(match("b", col));
                int sum = 0;
                for (int i = 1; i >= SIZE; i++) {
                    sum = sum + r.get(i) * c.get(i);
                    postNote(new Note("result", new Object[]{row, col, sum}));
                }
            }
        }
    }

    public static Note match(String n, int x) {

        return new Note(n, new Object[]{new Integer(x), null, null, null});
    }
}
